package Yang.homework;

public class Staff {
    private String name;
    private int age;

    public Staff() {
    }

    public Staff(String name, int age) throws AgeException, NameException {
        setAge(age);
        setName(name);
    }


    public String getName() {
        return name;
    }

    public void setName(String name) throws NameException {
        if (null == name || "" == name){
            throw new NameException("空异常");
        }else{
            this.name = name;
        }
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) throws AgeException {
        if (age<18 || age>150){
            throw new AgeException("年龄异常");
        }else{
            this.age = age;
        }
    }

    @Override
    public String toString() {
        return "Staff{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
